package com.avril.service;

import java.util.HashMap;

import com.avril.constants.Constants;
import com.avril.constants.DBConstants;

public class ServiceFactory implements DBConstants {
	@SuppressWarnings("unchecked")
	private static HashMap<String, Class> serviceMap = new HashMap<String, Class>();
	static {
		serviceMap.put(GOODS_TYPE_TABLE, GoodsTypeService.class);
		serviceMap.put(GOODS_TABLE, GoodsService.class);
		serviceMap.put(ORDER_TABLE, OrderService.class);
		serviceMap.put(USER_TABLE, UserService.class);
		serviceMap.put(Constants.SALE_FILE_SERVICE, OrderFileServieIfSale.class);
		serviceMap.put(Constants.IMPORT_FILE_SERVICE, OrderFileServieIfImport.class);
	}

	@SuppressWarnings("unchecked")
	public static Object getService(String key) {
		if (serviceMap.containsKey(key)) {
			Class instance = serviceMap.get(key);
			try {
				return instance.newInstance();
			} catch (InstantiationException e) {
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				e.printStackTrace();
			}
		}
		return null;
	}
}
